package net.oschina.team.note.bean;

import com.jfinal.plugin.activerecord.Model;

public class Notes extends Model<Notes> {
	private static final long serialVersionUID = -4510616867507785148L;

	public static Notes ME = new Notes();
	public static final int STATUS_NORMAL = 0;
	public static final int STATUS_HIDDEN = 1;
	
	/**
	 * 按照模版创建即时贴
	 * @param user
	 * @return
	 */
	public Notes createAsTemplate(long user,int x,int y,int z){
		String sql = "SELECT * FROM " + NotesTemplate.TABLENAME + " WHERE user = ?";
		NotesTemplate notesTem = NotesTemplate.ME.findFirst(sql, user);
		Notes notes = new Notes();
		boolean result = notes.set("content", notesTem.get("content")).set("user", user)
			.set("position_x", x).set("position_y", y).set("position_z", z)
			.set("width", notesTem.get("width")).set("height", notesTem.get("height")).set("color", notesTem.get("color"))
			.set("title_left", notesTem.get("title_left")).set("title_top", notesTem.get("title_top")).set("style_t", notesTem.get("style_t")).save();
		if(result){
			return notes;
		}else{
			return null;
		}
	}
}
